import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import axios from "axios";
import moment from 'moment';
import '@/assets/css/global.css'
import 'element-ui/lib/theme-chalk/index.css'
import MD5 from 'md5-hex'
import uploader from 'vue-simple-uploader'
Vue.use(ElementUI)
Vue.use(uploader)

Vue.prototype.$http=axios
axios.defaults.baseURL='/api'

Vue.config.productionTip = false

Vue.prototype.$md5=MD5

Vue.filter('dateFit',function (data,forStr) {
  return moment(data).format(forStr);
})

//axios提供拦截器，发送或响应之前或者之后都能拦截
// axios.interceptors.request.use((req)=>{
//   debugger
//   //获取token
//   let token = sessionStorage.getItem("token");
//   if(token!=null){
//     req.headers.token=token;
//   }
//   return req;
// });


router.beforeEach(function (to, from, next) {
  if(to.path=='/login'){
    return next();
  }
  let user=sessionStorage.getItem("user");
  if(user!=null){
    return next();
  }else {
    return next('/login');
  }

})



new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
